import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';
import 'package:finance_app/src/common/config.dart';
import 'package:finance_app/src/router_gen/router_gen_providers.dart';

class LoginInterceptor extends Interceptor {
  @override
  void onResponse(
    Response response,
    ResponseInterceptorHandler handler,
  ) async {
    if (response.data != null &&
        response.data is Map &&
        response.data['message'] == 'Unauthenticated.') {
      await Config.clearConfig();
      Routes.navigateTo(RouterGenProviders.loginPage,
          clearStack: true, isSingleTop: true);
    }

    handler.next(response);
  }
}
